﻿@{
    ViewData["Title"] = "添加PLC读取DB配置";
    Layout = "_Edit";
}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-add">
        <input type="hidden" class="input-text" value="@Model.ID" id="id" name="id">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>PLC名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.PlcName" placeholder="" id="PlcName" name="PlcName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>设备号</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.EquipmentCode" placeholder="" id="EquipmentCode" name="EquipmentCode">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>DB编号PLC：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.DbCode" placeholder="" id="DbCode" name="DbCode">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>DB编号WCS：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="DbCode2" name="DbCode2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>DB读取起始位：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.DbStart" placeholder="" id="DbStart" name="DbStart">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>DB读取长度：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.DbLength" placeholder="" id="DbLength" name="DbLength">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>报文处理模块类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ProcessModuleType" placeholder="" id="ProcessModuleType" name="ProcessModuleType">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>报文处理模块对象名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.ProcessModuleName" placeholder="" id="ProcessModuleName" name="ProcessModuleName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>任务名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="JobID" id="JobID">
                        <option value="0">--请选择--</option>
                        @foreach (var item in Model.JobSearchs)
                        {
                            if (Model.JobID + "" == item.JobId)
                            {
                                <option value="@item.JobId" selected>@item.JobName</option>
                            }
                            else
                            {
                                <option value="@item.JobId">@item.JobName</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>PLC连接IP：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" size="1" name="PlcConnectionID" id="PlcConnectionID">
                        <option value="0">--请选择--</option>
                        @foreach (var item in Model.PlcIpSearchs)
                        {
                            if (Model.PlcConnectionID + "" == item.PlcConnectId)
                            {
                                <option value="@item.PlcConnectId" selected>@item.PlcConnectIp - @item.ScEquipmentCode</option>
                            }
                            else
                            {
                                <option value="@item.PlcConnectId">@item.PlcConnectIp - @item.ScEquipmentCode</option>
                            }
                        }
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否心跳：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    @if (Model.IsHeartbeat)
                    {
                        <input name="IsHeartbeat" type="radio" id="IsHeartbeat-true" value="1" checked>
                    }
                    else
                    {
                        <input name="IsHeartbeat" type="radio" id="IsHeartbeat-true" value="1">

                    }
                    <label for="IsHeartbeat-true">是</label>
                </div>
                <div class="radio-box">
                    @if (Model.IsHeartbeat)
                    {
                        <input name="IsHeartbeat" type="radio" id="IsHeartbeat-false" value="0">
                    }
                    else
                    {
                        <input name="IsHeartbeat" type="radio" id="IsHeartbeat-false" value="0" checked>
                    }
                    <label for="IsHeartbeat-false">否</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否启用：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    @if (Model.IsEnable)
                    {
                        <input name="IsEnable" type="radio" id="IsEnable-true" value="1" checked>
                    }
                    else
                    {
                        <input name="IsEnable" type="radio" id="IsEnable-true" value="1">

                    }
                    <label for="IsEnable-true">是</label>
                </div>
                <div class="radio-box">
                    @if (Model.IsEnable)
                    {
                        <input name="IsEnable" type="radio" id="IsEnable-false" value="0">
                    }
                    else
                    {
                        <input name="IsEnable" type="radio" id="IsEnable-false" value="0" checked>
                    }
                    <label for="IsEnable-false">否</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>写入类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="ObjectType" name="ObjectType">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>PLC解析对象名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="PLCobjectName" name="PLCobjectName">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>WCS解析对象名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="WCSobjectName" name="WCSobjectName">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>对象长度：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="objectLength" name="objectLength">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>字节索引：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="BytesIndex" name="BytesIndex">
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input id="btnSubmit" class="btn btn-primary radius" type="button" onclick="operate()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

@section javascript{

    <script>
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        function operate() {
            var PlcName = $("#PlcName").val();
            if (PlcName == null || PlcName == "") {
                popupAlert('请输入PLC名称', 2, function (data) { layer.close(data); });
                return;
            }
            var IsHeartbeat = $("#IsHeartbeat").val();

            var IsEnable = $("#IsEnable").val();

            var EquipmentCode = $("EquipmentCode").val();
            var DbCode = $("#DbCode").val();
            if (DbCode == null || DbCode == "") {
                popupAlert('请输入DB编号', 2, function (data) { layer.close(data); });
                return;
            }

            var DbStart = $("#DbStart").val();
            if (DbStart == null || DbStart == "") {
                popupAlert('请输入DB读取起始位', 2, function (data) { layer.close(data); });
                return;
            }
            var DbLength = $("#DbLength").val();
            if (DbLength == null || DbLength == "") {
                popupAlert('请输入DB读取长度', 2, function (data) { layer.close(data); });
                return;
            }
            var ProcessModuleType = $("#ProcessModuleType").val();
            if (ProcessModuleType == null || ProcessModuleType == "") {
                popupAlert('请输入报文处理模块类型', 2, function (data) { layer.close(data); });
                return;
            }
            var ProcessModuleName = $("#ProcessModuleName").val();
            if (ProcessModuleName == null || ProcessModuleName == "") {
                popupAlert('请输入报文处理模块对象名称', 2, function (data) { layer.close(data); });
                return;
            }
            var JobID = $("#JobID").val();
            if (JobID == null || JobID == "" || JobID == 0) {
                popupAlert('请选择任务名称', 2, function (data) { layer.close(data); });
                return;
            }
            var PlcConnectionID = $("#PlcConnectionID").val();
            if (PlcConnectionID == null || PlcConnectionID == "" || PlcConnectionID == 0) {
                popupAlert('请选择PLC连接IP', 2, function (data) { layer.close(data); });
                return;
            }
            //var stamp=document.getElementById("btnSubmit");
            //stamp.disabled=true;
            $("#btnSubmit").attr("disabled", true);
            SubmitFormForAjax("/plcreaddb/AddPlcReadDBInfoAndMore", $("#form-add").serialize(), function (data) {
                if (data.result) {
                    $("#btnSubmit").attr("disabled", false);
                    popupAlert('提交成功', 1, function () { closePageLayer(true); });
                } else {
                    $("#btnSubmit").attr("disabled", false);
                    popupAlert(data.message, 2, function (data) { layer.close(data); });
                }
            }, true);
        }
    </script>
}